package com.hutao.medical.common.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.apache.poi.ss.usermodel.DataFormat;

public class DateUtil {

private static SimpleDateFormat  dateFormat;
	
	/**
	 * 字符串转换为date
	 * @param format
	 * 			格式花样�?
	 * @param strDate
	 * 			时间字符�?
	 * @return
	 * @throws ParseException
	 */
	public static  Date strToDate(String format,String strDate) throws ParseException{
		dateFormat=new SimpleDateFormat(format);
		return dateFormat.parse(strDate);
		
	}
	
	public static  String dateToStr(Date strDate) throws ParseException{
		dateFormat=new SimpleDateFormat("yyyy-MM-dd");
		return dateFormat.format(strDate);
		
	} 
	
	public static  String dateToStr(Date strDate,String format) throws ParseException{
		dateFormat=new SimpleDateFormat(format);
		return dateFormat.format(strDate);
		
	} 
	
	public static Date strToDate(String dateStr){
		Date date=null;
		try {
			SimpleDateFormat format=new SimpleDateFormat("yyyy-MM-dd");
			date = format.parse(dateStr);
		} catch (Exception e) {
			// TODO: handle exception
		}
		return date;
	}
}
